﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using Newtonsoft.Json;
namespace STHPMS1.Web.W_View.Survey
{
    /// <summary>
    /// UploadHanlder 的摘要说明
    /// </summary>
    public class UploadHanlder : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            HttpFileCollection files = context.Request.Files;
            string uploadPath =
                HttpContext.Current.Server.MapPath("~/App_Data/Upload") + "\\";

            if (files.Count > 0)
            {
                if (!Directory.Exists(uploadPath))
                {
                    Directory.CreateDirectory(uploadPath);
                }
                string fileName = uploadPath + files[0].FileName;
                files[0].SaveAs(fileName);



                context.Response.Write(fileName);
                context.Response.End();
            }
            else
            {
                context.Response.Write("0");
                context.Response.End();
            }  
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}